<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>列表渲染</h2>
      <ul>
        <!-- v-for指令可以提供第二个参数，表示索引 -->
        <!-- <li v-for="(item, index) in items">{{ item.message }} - {{ index }}</li> -->
        <li v-for="({message}, index) in items">{{ message }} - {{ index }}</li>
      </ul>

      <div v-for="item in list">
        <div v-for="value of item.children">{{ value.name }}</div>
      </div>

      <hr />

      <h2>对象使用v-for</h2>
      <ul>
        <!-- v-for遍历对象的时候，有三个参数value,key,index -->
        <li v-for="(value, key, index) in myObject">
          {{ value }} - {{ key }} - {{ index }}
        </li>
      </ul>

      <h2>v-for使用范围值</h2>
      <ul>
        <!-- 5相当于 [1,2,3,4,5] -->
        <li v-for="item in 5">{{ item }}</li>
      </ul>
      <div v-for="item in 9">
        <span v-for="value in item" style="display: inline-block; width: 120px">
          {{ value }} * {{ item }} = {{ value * item }}
        </span>
      </div>
    </div>

    <script src="./lib/Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            items: [{ message: "Foo" }, { message: "Bar" }],
            list: [
              {
                name: "zhangsan",
                children: [
                  {
                    name: "lisi",
                  },
                  {
                    name: "wangwu",
                  },
                ],
              },
              {
                name: "zhaoliu",
                children: [
                  {
                    name: "sunqi",
                  },
                  {
                    name: "wangba",
                  },
                ],
              },
            ],
            myObject: {
              title: "How to do lists in Vue",
              author: "Jane Doe",
              publishedAt: "2016-04-10",
            },
          };
        },
      }).mount("#app");
    </script>
  </body>
</html>
